Skip to content

Conversation

Christopher96u
Copy link
Contributor

@Christopher96u Christopher96u commented Oct 5, 2025

Summary

  • tighten useServerFn typing in React/Solid so inline useMutation({ mutationFn: useServerFn(fn) })
    resolves to the awaited payload instead of unknown
  • add a focused .test-d.tsx regression exercising the React Query reproduction
  • restore the basic React Query example with a simple server function + mutation flow
  • Fixes Broken type for useServerFn inside useMutation #5352
  • Updated 1 example to use useServerFn (I can remove it if I should?)

Summary by CodeRabbit

  • New Features

    • Example app adds a server-side mutation flow with a “Say hi” button and vertical layout that displays the greeting on success.
  • Refactor

    • Revised useServerFn return shape and behavior for React and Solid to provide more consistent, ergonomic return types.
  • Tests

    • Added integration/regression tests for server-function usage with mutations in React and Solid.

Copy link

nx-cloud bot commented Oct 5, 2025

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 2e28196

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 6m 6s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-05 11:06:00 UTC

Copy link
Contributor

coderabbitai bot commented Oct 5, 2025

Walkthrough

Refactors useServerFn in React and Solid to a conditional, arity-aware return type and named handler; adds example wiring of a server-side mutation in the React example and new d.ts tests for React and Solid demonstrating useServerFn with React Query and various invocation shapes.

Changes

Cohort / File(s) Summary
Example: React Query mutation wiring
examples/react/start-basic-react-query/src/routes/index.tsx
Adds greetUser server function (POST + input validation) and wires it into useMutation via useServerFn(greetUser); updates layout, adds "Say hi" button to trigger mutation and conditionally render the greeting.
React runtime & types
packages/react-start/src/useServerFn.ts
Adds internal types (AwaitedReturn, NonUndefined, UseServerFnReturn<T>); changes exported useServerFn signature to return UseServerFnReturn<T>; refactors to a named handler via React.useCallback; adds explicit casts for success and redirect paths.
React tests (types)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx
New d.ts test demonstrating createServerFn + .inputValidator() + .handler() and using useServerFn(serverFn) as a mutationFn for useMutation, including typed onSuccess access and optional invocation patterns.
Solid runtime & types
packages/solid-start/src/useServerFn.ts
Mirrors React changes: introduces AwaitedReturn, NonUndefined, UseServerFnReturn<T>; updates exported useServerFn signature to return UseServerFnReturn<T>; implements a named handler with typed success and redirect handling.
Solid tests (types)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx
Adds d.ts test exercising mandatory and optional serverFns with useServerFn, including component and hook examples calling returned handlers and asserting typed shapes for success and void/undefined variants.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Home Component
  participant RQ as React Query
  participant Adapter as useServerFn(handler)
  participant Server as Server Function (greetUser)

  User->>UI: Click "Say hi"
  UI->>RQ: mutate({ name: "TanStack" })
  RQ->>Adapter: call mutationFn(args)
  Adapter->>Server: POST /greetUser { name }
  Server-->>Adapter: { message }
  Adapter-->>RQ: { message }
  RQ-->>UI: onSuccess(data)
  UI-->>User: Render greeting
Loading
sequenceDiagram
  autonumber
  participant Cmp as Component
  participant Hook as useServerFn(handler)
  participant Router as Router
  participant Server as Server Function

  Cmp->>Hook: call handler(...args)
  Hook->>Server: invoke
  alt Redirect thrown
    Server-->>Hook: RedirectError
    Hook->>Router: navigate(redirectTarget)
    Router-->>Hook: navigation result
    Hook-->>Cmp: navigation result (cast as AwaitedReturn)
  else Success
    Server-->>Hook: result
    Hook-->>Cmp: result (AwaitedReturn)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • schiller-manuel
  • chorobin

Poem

A hop, a POST, a friendly ping,
I nibble types until they sing.
Mutations hop and handlers spring,
Greetings bloom from tiny things.
🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the primary changes by noting the fix to the inferred types of useServerFn and the addition of a type test, which directly reflects the main objectives of the pull request.
Linked Issues Check ✅ Passed The pull request implements the improved UseServerFnReturn typing in both React and Solid packages, adds focused .test-d.tsx regression tests for inline useServerFn in useMutation, and restores the basic React Query example, fully addressing the objectives from issue #5352 to restore correct onSuccess types.
Out of Scope Changes Check ✅ Passed All code modifications are centered on tightening useServerFn typings, adding regression tests, and example restoration, with no unrelated or out-of-scope changes detected outside the objectives of issue #5352.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

pkg-pr-new bot commented Oct 5, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5367

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5367

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5367

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5367

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5367

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5367

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5367

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5367

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5367

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5367

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5367

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5367

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5367

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5367

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5367

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5367

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5367

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5367

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5367

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5367

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5367

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5367

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5367

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5367

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5367

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5367

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5367

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5367

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5367

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5367

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5367

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5367

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5367

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5367

commit: 2e28196

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc32014 and 0cf8f24.

📒 Files selected for processing (4)
  • examples/react/start-basic-react-query/src/routes/index.tsx (1 hunks)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
  • packages/react-start/src/useServerFn.ts (1 hunks)
  • packages/solid-start/src/useServerFn.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/react-start/src/useServerFn.ts
  • packages/solid-start/src/useServerFn.ts
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
  • examples/react/start-basic-react-query/src/routes/index.tsx
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/react-start/src/useServerFn.ts
  • packages/solid-start/src/useServerFn.ts
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
**/src/routes/**

📄 CodeRabbit inference engine (AGENTS.md)

Place file-based routes under src/routes/ directories

Files:

  • examples/react/start-basic-react-query/src/routes/index.tsx
examples/{react,solid}/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep example applications under examples/react/ and examples/solid/

Files:

  • examples/react/start-basic-react-query/src/routes/index.tsx
🧬 Code graph analysis (4)
packages/react-start/src/useServerFn.ts (1)
packages/solid-start/src/useServerFn.ts (1)
  • useServerFn (14-41)
packages/solid-start/src/useServerFn.ts (1)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (15-45)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (15-45)
examples/react/start-basic-react-query/src/routes/index.tsx (2)
e2e/react-start/server-functions/src/routes/formdata-redirect/index.tsx (1)
  • greetUser (16-33)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (15-45)
🪛 Biome (2.1.2)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx

[error] 11-11: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)


[error] 9-10: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview

@Christopher96u
Copy link
Contributor Author

It looks there are few tweaks I need to do

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf8f24 and 7104281.

📒 Files selected for processing (3)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
  • packages/react-start/src/useServerFn.ts (1 hunks)
  • packages/solid-start/src/useServerFn.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-start/src/useServerFn.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/solid-start/src/useServerFn.ts
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/solid-start/src/useServerFn.ts
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
🧬 Code graph analysis (2)
packages/solid-start/src/useServerFn.ts (1)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (21-51)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (21-51)
🪛 Biome (2.1.2)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx

[error] 11-11: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)


[error] 9-10: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)


[error] 20-21: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)


[error] 24-25: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (3)

4-10: Consider removing redundant Promise wrapping.

The await Promise.resolve() is unnecessary since the handler is already async. Simplifying to return { message: \Hello ${data.name}!` }` would be cleaner.

Apply this diff:

 const serverFn = createServerFn({ method: 'POST' })
   .inputValidator((input: { name: string }) => input)
   .handler(async ({ data }) => {
-    return await Promise.resolve({
-      message: `Hello ${data.name}!`,
-    })
+    return {
+      message: `Hello ${data.name}!`,
+    }
   })

12-16: Consider removing redundant Promise wrapping.

Same as above - the await Promise.resolve() is unnecessary. Simplify to return { ok: true as const }.

Apply this diff:

 const optionalServerFn = createServerFn().handler(async () => {
-  return await Promise.resolve({
-    ok: true as const,
-  })
+  return {
+    ok: true as const,
+  }
 })

18-29: Consider adding explicit type assertions for robustness.

While TypeScript compilation verifies the types, using explicit type assertions (e.g., expectTypeOf from vitest or tsd) would make the test more robust and self-documenting. This would catch regressions even if TypeScript's inference changes subtly.

Example approach:

import { expectTypeOf } from 'vitest'

export function UseServerFnMutationRegressionComponent() {
  const mutation = useMutation({
    mutationFn: useServerFn(serverFn),
    onSuccess: (data, variables) => {
      expectTypeOf(data).toHaveProperty('message')
      expectTypeOf(data.message).toBeString()
      expectTypeOf(variables?.data?.name).toEqualTypeOf<string | undefined>()
    },
  })

  void mutation
  return null
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7104281 and aea930f.

📒 Files selected for processing (2)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
🧬 Code graph analysis (2)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1)
  • useOptionalServerFnRegressionHook (31-40)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (2)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (21-51)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1)
  • useOptionalServerFnRegressionHook (28-37)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (6)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1)

31-40: LGTM!

This hook correctly tests the optional parameter scenario, verifying that useServerFn returns a callable handler that properly types the result. The test covers both invocation styles (handler() and handler(undefined)) and verifies the result shape.

packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (5)

1-2: LGTM!

The imports are correct for testing server function type inference.


3-9: LGTM!

The server function definition with input validation and handler is correctly structured. The handler properly destructures the validated input from the data property.


11-15: LGTM!

The optional server function definition is correct. The use of as const for the ok property ensures precise type inference (true rather than boolean).


24-24: Clarify the intent of voiding the handler reference.

This line voids the handler reference itself rather than calling it. In the React version (relevant code snippet from packages/react-start/src/tests/useServerFnMutation.test-d.tsx), the equivalent test calls the handler: void optionalHandler() and void optionalHandler(undefined).

If the intent is to test that the handler can be used in void expression contexts, consider making this explicit with a comment. Otherwise, consider calling the handler like void handler({ name: 'TanStack' }) to match the pattern used for the optional handler (lines 35-36).


28-37: LGTM!

The optional server function usage correctly tests various call signatures (no arguments, explicit undefined) and verifies that the return type is properly inferred (accessing result.ok). This aligns well with the React equivalent in the relevant code snippets.

export function UseServerFnRegressionComponent() {
const handler = useServerFn(serverFn)

handler({ data: { name: 'TanStack' } }).then((result) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix the input type mismatch.

The handler is being called with { data: { name: 'TanStack' } }, but the input validator (line 4) expects { name: string }. The data property wrapper is used server-side within the handler, not in the client-side call signature.

Apply this diff to fix the call:

-  handler({ data: { name: 'TanStack' } }).then((result) => {
+  handler({ name: 'TanStack' }).then((result) => {
     result.message
   })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
handler({ data: { name: 'TanStack' } }).then((result) => {
handler({ name: 'TanStack' }).then((result) => {
result.message
})
🤖 Prompt for AI Agents
In packages/solid-start/src/tests/useServerFnMutation.test-d.tsx around line 20,
the test calls handler({ data: { name: 'TanStack' } }) but the input validator
expects a plain { name: string }; remove the unnecessary data wrapper and call
handler({ name: 'TanStack' }) instead so the argument matches the declared input
type used by the validator.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (2)

4-10: Consider simplifying the async handler.

The await Promise.resolve() wrapper is redundant since async functions automatically wrap return values in a Promise. For clarity, consider simplifying to:

-  .handler(async ({ data }) => {
-    return await Promise.resolve({
-      message: `Hello ${data.name}!`,
-    })
-  })
+  .handler(async ({ data }) => {
+    return {
+      message: `Hello ${data.name}!`,
+    }
+  })

12-16: Consider simplifying the async handler.

Similar to the previous handler, the await Promise.resolve() wrapper is unnecessary:

-const optionalServerFn = createServerFn().handler(async () => {
-  return await Promise.resolve({
-    ok: true as const,
-  })
-})
+const optionalServerFn = createServerFn().handler(async () => {
+  return {
+    ok: true as const,
+  }
+})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aea930f and 37e55f3.

📒 Files selected for processing (1)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
🧬 Code graph analysis (1)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (2)
packages/react-start/src/useServerFn.ts (1)
  • useServerFn (21-51)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1)
  • useOptionalServerFnRegressionHook (28-37)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (3)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (3)

1-2: LGTM!

Imports are appropriate for testing the React Query integration with server functions.


18-29: Excellent regression test for issue #5352.

This component effectively validates that useServerFn inlined within useMutation preserves correct type inference. The onSuccess callback accessing data.message and variables.data.name would fail to compile if types regressed to unknown, making this a robust type-level guard against future regressions.


31-40: LGTM!

This hook properly tests the optional parameter handling for useServerFn, ensuring that both zero-argument and explicit undefined invocations work correctly while preserving type inference for the result.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1)

16-18: Fix the input type mismatch.

The handler is being called with { data: { name: 'TanStack' } }, but the input validator (line 4) expects { name: string }. The data property wrapper is used server-side within the handler, not in the client-side call signature.

Apply this diff to fix the call:

-  handler({ data: { name: 'TanStack' } }).then((result) => {
+  handler({ name: 'TanStack' }).then((result) => {
     result.message
   })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37e55f3 and 2e28196.

📒 Files selected for processing (2)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-start/src/tests/useServerFnMutation.test-d.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/solid-start/src/tests/useServerFnMutation.test-d.tsx
🧬 Code graph analysis (1)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (1)
packages/react-start/src/tests/useServerFnMutation.test-d.tsx (1)
  • useOptionalServerFnRegressionHook (27-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (4)
packages/solid-start/src/tests/useServerFnMutation.test-d.tsx (4)

1-2: LGTM!

The imports are correctly structured for a test file in this location.


3-7: LGTM!

The server function definition correctly uses input validation and the handler pattern.


9-11: LGTM!

The optional server function definition is appropriate for testing scenarios without input validation.


24-33: LGTM!

The optional server function test correctly exercises various invocation patterns, including no arguments, undefined, and void contexts. This provides good coverage for the type inference scenarios.

result.message
})

void handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Incomplete void context test.

Line 20 uses void handler which only references the handler without calling it. This doesn't effectively test the handler's behavior in a void context. Based on the React equivalent test (lines 31-32 in the relevant snippets), this should call the handler.

Apply this diff to call the handler in a void context:

-  void handler
+  void handler({ name: 'TanStack' })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void handler
void handler({ name: 'TanStack' })
🤖 Prompt for AI Agents
In packages/solid-start/src/tests/useServerFnMutation.test-d.tsx around line 20,
the test currently uses "void handler" which only references the handler instead
of invoking it; change this to call the handler in a void context (e.g., use
"void handler()" so the handler is executed) to match the React equivalent test
and properly verify void-context behavior.

@Christopher96u
Copy link
Contributor Author

I think I finished on this, but one test is failing, it doesn't look related to my changes, could someone have a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken type for useServerFn inside useMutation
1 participant